package com.open.party.cloud.view.home.jiCengDangJian.org.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.open.party.cloud.R;
import com.open.party.cloud.model.OrgDeptBean;
import com.sinothk.android.utils.XUtils;
import com.sinothk.view.image.rounded.RoundedImageView;

import java.util.ArrayList;
import java.util.List;

import com.sinothk.android.utils.inters.OnSuperListener;

public class OrgForCityCommListAdapter extends RecyclerView.Adapter<OrgForCityCommListAdapter.ViewHolder> {

    // 展示数据
    private ArrayList<OrgDeptBean> mData;
    private Context mContext;
    private OnSuperListener<OrgDeptBean> onSuperListener;

    public OrgForCityCommListAdapter(Context mContext) {
        this.mContext = mContext;
        this.mData = new ArrayList<>();
    }

    public void setOnSuperListener(OnSuperListener<OrgDeptBean> onSuperListener) {
        this.onSuperListener = onSuperListener;
    }

    public void setData(List<OrgDeptBean> data) {
        if (mData == null) {
            mData = new ArrayList<>();
        } else {
            mData.clear();
        }
        if (data == null) {
            data = new ArrayList<>();
        }
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    public void updateData(List<OrgDeptBean> data) {
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.org_city_comm_list_item, viewGroup, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        // 绑定数据
        final OrgDeptBean itemData = mData.get(position);

        holder.userNameTv.setText(XUtils.string().getNotNullValue(itemData.getName()));
//        holder.leaderTv.setText(XUtils.string().getNotNullValue(itemData.getOrgadmin()));
//        holder.phoneNumTv.setText(XUtils.string().getNotNullValue(itemData.getTelcode()));

//
//        if (itemData.getPartyType() != null && XUtils.string().isNotEmpty(itemData.getPartyType().getDesc())) {
//            holder.subTv.setText(itemData.getPartyType().getDesc());
//        }

//
//        String timeStr = "";
//        if (itemData.getReleaseTime() == null) {
//            timeStr = "最近";
//        } else {
//            timeStr = XUtils.date().getFriendlyDate(itemData.getReleaseTime());
//        }
//        holder.timeTv.setText(timeStr);
//
//        Picasso.get().load(itemData.getImgUrl())
//                .error(R.drawable.default_img)
//                .placeholder(R.drawable.default_img)
//                .into(holder.imageView);

        if (onSuperListener != null) {
            holder.rootView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onSuperListener.onClick(position, itemData, "rootView");
                }
            });
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        RelativeLayout rootView;
        TextView userNameTv, phoneNumTv, leaderTv;//, subTv, parStatusTv, durationTv, jianBaoTv, scoreTv;
        RoundedImageView imageView;

        ViewHolder(View itemView) {
            super(itemView);
            rootView = itemView.findViewById(R.id.rootView);

            userNameTv = itemView.findViewById(R.id.userNameTv);
//            phoneNumTv = itemView.findViewById(R.id.phoneNumTv);
//            leaderTv = itemView.findViewById(R.id.leaderTv);

//            parStatusTv = itemView.findViewById(R.id.parStatusTv);
//            durationTv = itemView.findViewById(R.id.durationTv);
//            scoreTv = itemView.findViewById(R.id.scoreTv);
//
//            jianBaoTv = itemView.findViewById(R.id.jianBaoTv);
//            imageView = itemView.findViewById(R.id.imageView);
        }
    }
}